package com.zp.crm.service.ServeService.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.zp.crm.dao.ServeDao.ServeDao;
import com.zp.crm.dto.Serve.ServeDto;
import com.zp.crm.entity.ServeEntity.ServeEntity;
import com.zp.crm.service.MenuService.MenuService;
import com.zp.crm.service.ServeService.ServeService;
import com.zp.crm.util.targetLog.Log;
@Service("serveSeivce")
public class ServeServiceImpl implements ServeService {
	@Resource
	public ServeDao serveDao;
	@Resource
	public MenuService menuService;
	@Log(name="服务信息添加操作 ")
	@Override
	public Map<String, Object> insert(ServeEntity entity) {
		Map<String, Object> map=new HashMap<>();
		
		int r=serveDao.insert(entity);
		
		if(r>0){
			map.put("success", true);
			map.put("message", "服务创建成功！");
		}else{
			map.put("success", false);
			map.put("message", "服务创建失败！");
		}
		return map;
	}
	@Log(name="服务信息进行分配 ")
	//分配人员
	@Override
	public Map<String, Object> allotUpdate(ServeEntity entity) {
		Map<String, Object> map=new HashMap<>();
			
		int r=serveDao.allotUpdate(entity);
		
		if(r>0){
			map.put("success", true);
			map.put("message", "分配人员成功 !");
		}else{
			map.put("success", false);
			map.put("message", "分配人员失败！请稍后从试");
		}
		
		return map;
	}
	@Log(name="查询到拥有服务角色的用户并封装成下拉列表形式 ")
	@Override
	public Map<String, Object> ListPage(String html,String stuts,String code,String listType, int page, int size) {
			Map<String, Object> map=new HashMap<>();
			int PageIndex=(page-1)*size;
			int countList=serveDao.createPageCount(code,stuts);
			List<ServeEntity> list=serveDao.createPage(code,stuts,PageIndex,size);
			Map<String, Object> menuMap=menuService.menuZDCreate("服务角色");
			String t="";
			if((boolean) menuMap.get("success")){
				t=(String) menuMap.get("message");
			}
			String a=new ServeDto().AllotHtml(countList,list,page,0,html,t);
			map.put("message", a);
		return map;
	}
	@Log(name="服务信息根据Id查询指定信息 ")
	@Override
	public Map<String, Object> SelectById(int id) {
		Map<String, Object> map=new HashMap<>();
		ServeEntity entity=serveDao.selectById(id);
		if(entity != null){
			map.put("success", true);
			map.put("message", entity);
		}else{
			map.put("success", false);
			map.put("message", "系统错误！请从试！");
		}
		
		return map;
	}
	@Log(name="服务信息根据条件查询并分页，转换成Html页面形式 ")
	@Override
	public Map<String, Object> ListCreatePage(String name, String gy, String type, String onetime, String twotime,
			String html, String stuts, String code, String listType, int page, int size) {
		Map<String, Object> map=new HashMap<>();
		if(name != null || gy != null || type != null || onetime != null || twotime !=null){
			int PageIndex=(page-1)*size;
			int countList=serveDao.SelectCratePageCount(code,stuts,name,gy,type,onetime,twotime);
			List<ServeEntity> list=serveDao.SelectCreatePage(code,stuts,PageIndex,size,name,gy,type,onetime,twotime);
			Map<String, Object> menuMap=menuService.menuZDCreate("服务角色");
			String t="";
			if((boolean) menuMap.get("success")){
				t=(String) menuMap.get("message");
			}
			String a=new ServeDto().AllotHtml(countList,list,page,1,html,t);
			map.put("message", a);
		}else{
			map=ListPage(html,stuts,code,listType,page,size);
		}
		return map;
	}
	@Log(name="服务信息修改状态 ")
	@Override
	public Map<String, Object> ServeStutsById(ServeEntity entity) {
		Map<String, Object> map=new HashMap<>();
		
		int r=serveDao.ServeStutsById(entity);
		
		if(r>0){
			map.put("success", true);
			map.put("message", "操作成功！");
		}else{
			map.put("success", false);
			map.put("message", "操作失败！");
		}
		
		return map;
	}
	@Log(name="服务信息删除 ")
	@Override
	public Map<String, Object> deleteById(int id) {
		Map<String, Object> map=new HashMap<>();
		
		int r=serveDao.deleteById(id);
		
		if(r>0){
			map.put("success", true);
			map.put("message", "删除信息成功！");
		}else{
			map.put("success", false);
			map.put("message", "删除信息失败！");
		}
		

		return map;
	}
}
